package com.ftg.rbac.mapper;

import java.util.List;

import com.ftg.rbac.dto.UserDto;
import com.ftg.rbac.dto.UserUpdateDto;
import com.ftg.rbac.entity.User;
import com.ftg.rbac.vo.UserListVo;
import org.apache.ibatis.annotations.*;

/**
 * 用户管理
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/3/16 上午9:08
 */
public interface UserMapper {

    /**
     * 主键删除
     * @param id  主键
     * @return
     */
    @Delete("delete from user where uid = #{id}")
    int deleteUser(@Param("id") Integer id);

    @Select("select * from user where uid = #{id}")
    User findOneById(@Param("id") Integer id);

//    @Select("select count(uid) from user")
    int countUser(
            @Param("unickname") String unickname,
            @Param("utel") String utel,
            @Param("ustate") boolean ustate,
            @Param("ucreatedate1") String ucreatedate1,
            @Param("ucreatedate2") String ucreatedate2
          );

//    @Select("select uid, uname, unickname, utel, usex, pid, did," +
//            " uemail, upass, ustate, rid, uremark, ucreatedate from user limit #{start},#{end}")
    List<UserListVo> listForAll(
            @Param("unickname") String unickname,
            @Param("utel") String utel,
            @Param("ustate") boolean ustate,
            @Param("ucreatedate1") String ucreatedate1,
            @Param("ucreatedate2") String ucreatedate2,
            @Param("start") Integer start,@Param("end")Integer end);


    @Select("select count(uid) from user where uname = #{uname}")
    int findNumByUname(@Param("uname") String uname);


    @Insert("insert into user(uname, unickname, utel, usex, pid, did, uemail, upass, ustate, rid, uremark, ucreatedate)" +
            "values (#{uname},#{unickname},#{utel},#{usex},#{pid},#{did},#{uemail},#{upass},#{ustate},#{rid},#{uremark},#{ucreatedate})")
    int saveUser(UserDto userDto);

    @Update("update user set " +
            "unickname=#{unickname}, " +
            "utel=#{utel}, " +
            "usex=#{usex}, " +
            "pid=#{pid}, " +
            "did=#{did}, " +
            "uemail=#{uemail},  " +
            "ustate=#{ustate}, " +
            "rid=#{rid}, " +
            "uremark=#{uremark} where uid=#{uid}")
    int modifyUserById(UserUpdateDto userUpdateDto);
}
